﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FeaturesBlog.Models.Repositories;
using FeaturesBlog.Models.Interfaces;


namespace FeaturesBlog.Models
{
    public class DataManager : IDataManager
    {
        #region Variables
        private MyFeaturesBlogClassesDataContext _dataContext;
        private IPostRepository _postRepository;
        private IUserRepository _userRepository;
        private ICommentsRepository _commentsRepository;
        private IUserEmailRepository _userEmailRepository;
        private static DataManager _self;
        #endregion

        #region Properties
        public IPostRepository PostRepository
        {
            get
            {
                if (_postRepository == null)
                {
                    _postRepository = new PostRepository(_dataContext);
                }
                return _postRepository;
            }
            set
            {
                _postRepository = value;
            }
        }
        public IUserRepository UserRepository
        {
            get
            {
                if (_userRepository == null)
                {
                    _userRepository = new UserRepository(_dataContext);
                }
                return _userRepository;
            }
            set
            {
                _userRepository = value;
            }
        }
        public ICommentsRepository CommentsRepository
        {
            get
            {
                if (_commentsRepository == null)
                {
                    _commentsRepository = new CommentsRepository(_dataContext);
                }
                return _commentsRepository;
            }
            set
            {
                _commentsRepository = value;
            }
        }
        public IUserEmailRepository UserEmailRepository
        {
            get
            {
                if (_userEmailRepository == null)
                {
                    _userEmailRepository = new UserEmailRepository(_dataContext);
                }
                return _userEmailRepository;
            }
            set
            {
                _userEmailRepository = value;
            }
        }
        #endregion

        #region Methods
        public DataManager()
        {
            _dataContext = new MyFeaturesBlogClassesDataContext();
            _self = this;
        }
        /*public static DataManager DataManagerInstance()
        {
            if (_self == null)
            {
                _self = new DataManager();
            }
            return _self;
        }*/
        #endregion

    }
}
